package org.allen.aspect;

import lombok.extern.slf4j.Slf4j;
import org.allen.utils.FieldAutowiredUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @Author: Allen
 * @Date: Created in 17:11 2019-09-26
 * @Description:
 */
@Component
@Aspect
@Slf4j
public class FieldAutowiredAspect {

    @Autowired
    private FieldAutowiredUtils fieldAutowiredUtils;

    @Around("@annotation(org.allen.annotation.FieldAutowiredEnable)")
    public Object handle(ProceedingJoinPoint proceedingJoinPoint) {
        try {
            Object proceed = proceedingJoinPoint.proceed();
            fieldAutowiredUtils.autoWired(proceed);
            return proceed;
        } catch (Throwable throwable) {
            log.error(throwable.getMessage() ,throwable);
        }
        return null;
    }


}
